jQuery('tbody#user_body').html('<%= escape_javascript render("sub_users") %>');
jQuery("table.table_listing").trigger('update');

jQuery('#sort_direction').html('<%= params[:direction]%>');
// Add page params in table listing headers
jQuery(".sortable").each(function () {

    var href = jQuery(this).attr('href');
    var qs = href.split('?')[1];
    var qsa = [];

    jQuery(qs.split('&')).each(function () {
        var key = this.split('=')[0];
        var value = this.split('=')[1];
        if (key == 'page')
            value = <%= params[:page] || 1%>;
        if(key == 'direction' && value == 'asc')
            value = 'desc';
        else if(key == 'direction' && value == 'desc')
            value = 'asc';

        qsa.push(key + "=" + value);
    });

    var new_qs = href.split('?')[0] + '?' + qsa.join('&');
    jQuery(this).attr('href', new_qs);
});